<%= form_with model: [:profile, @api_key], data: { controller: "exclusive-checkbox gem-scope" } do |f| %>
  <%= label_tag :name, t("api_keys.index.name"), class: "form__label" %>
  <%= f.text_field :name, class: "form__input", autocomplete: :off, disabled: f.object.persisted? %>

  <div class="form__group">
    <%= label_tag :scope, t(".exclusive_scopes"), class: "form__label" %>
    <% ApiKey::EXCLUSIVE_SCOPES.each do |api_scope| %>
      <div class = "form__checkbox__item">
        <%= api_key_checkbox(f, api_scope) %>
        <%= label_tag api_scope, t("api_keys.index.#{api_scope}"), class: "form__checkbox__label" %>
      </div>
    <% end %>
  </div>
  <div class="form__group">
    <%= label_tag :scope, t("api_keys.index.scopes"), class: "form__label" %>
    <% (ApiKey::API_SCOPES - ApiKey::EXCLUSIVE_SCOPES).each do |api_scope| %>
      <div class = "form__checkbox__item">
        <%= api_key_checkbox(f, api_scope) %>
        <%= label_tag api_scope, t("api_keys.index.#{api_scope}"), class: "form__checkbox__label" %>
      </div>
    <% end %>
  </div>

  <div class="form__group api_key_rubygem_id_form">
    <%= label_tag :rubygem_id, t(".rubygem_scope"), class: "form__label" %>
    <p><%= t(".rubygem_scope_info") %></p>
    <%= f.collection_select :rubygem_id, current_user.rubygems.by_name, :id, :name, { include_blank: t("api_keys.all_gems") }, selected: :rubygem_id, class: "form__input form__select", data: { gem_scope_target: "selector" } %>
  </div>

  <div class="form__group">
    <%= label_tag :expires_at, t(".expiration"), class: "form__label" %>
    <%= f.datetime_field :expires_at, min: 5.minutes.from_now, include_seconds: false, class: "form__input", disabled: f.object.persisted?  %>
  </div>

  <% unless current_user.mfa_disabled? || current_user.mfa_ui_and_api? %>
    <div class="form__group">
      <%= label_tag :mfa, t(".multifactor_auth"), class: "form__label" %>
      <div class="form__checkbox__item">
        <%= f.check_box :mfa, { class: "form__checkbox__input", id: :mfa, checked: true } , "true", "false" %>
        <%= label_tag :mfa, t(".enable_mfa"), class: "form__checkbox__label" %>
      </div>
    </div>
  <% end %>

  <%= f.submit class: "form__submit" %>
<% end %>
